﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.AcmsControls.ContentControls.Admin
{
    [ToolboxData("<{0}:BaseCustomAdminControl runat=server></{0}:BaseCustomAdminControl>")]
    public class BaseCustomAdminControl : UserControl
    {
        public Acms.AcmsControls.AcmsContext AcmsContext { get; set; }
        public Acms.Bll.UserPrinciple User { get; set; }

        protected string ResolveCustomControlPath(string userControlPath)
        {
            string existsingQS = null;
            string url = userControlPath;
            if (userControlPath.Contains("?"))
            {
                url = userControlPath.Substring(0, userControlPath.IndexOf("?"));
                existsingQS = userControlPath.Substring(userControlPath.IndexOf("?") + 1);
            }

            if (Request.ApplicationPath.EndsWith("/acms", StringComparison.InvariantCultureIgnoreCase))
            {
                url = url.Replace("~/", "~/CustomAdmin/");
            }

            System.Text.StringBuilder tmp = new StringBuilder();
            tmp.Append(Request.AppRelativeCurrentExecutionFilePath);
            tmp.AppendFormat("?Name={0}", Server.UrlEncode(Request.QueryString["Name"]));
            tmp.AppendFormat("&Path={0}", Server.UrlEncode(url));
            if (!string.IsNullOrEmpty(existsingQS))
            {
                tmp.AppendFormat("&{0}", existsingQS);
            }
            return tmp.ToString();
        }

        public virtual void GetExtaBreadCrumbs(Dictionary<string, string> extaItems)
        {
        }
    }
}
